<?php
    class Error
    {
        #region Fields
        private $text = 'Error.';
        private $code = 0;
        
        private static $codesMessages = array(
            'Undefined error.',
            'Insufficient rights.'
        );
        #endregion
        
        #region Constructors / destructor
        function __construct($text, $code)
        {
            $this->text = $text;
            $this->code = $code;
        }
        
        function __destruct()
        {
            
        }
        #endregion
        
        #region Accessors
        function __get($name)
        {
            switch ($name)
            {
                case 'text':
                    return $this->text;
                    break;
                case 'code':
                    return $this->code;
                    break;
                default:
                    break;
            }
        }
        
        function __set($name, $value)
        {
            switch ($name)
            {
                case 'text':
                    if (is_string($value))
                    {
                        $this->text = $value;
                    }
                    break;
                case 'code':
                    if (is_int($value))
                    {
                        $this->code = $value;
                    }
                    break;
                default:
                    break;
            }
        }
        #endregion
        
        #region Methods
        function show()
        {
            echo '<section><p>Erreur - ' . $this->text . '<br />[code n°' . $this->code . '] - ' . Error::$codesMessages[$this->code] . '</p></section>';
        }
        #endregion
    }
?>
